
//
//  CustomLayout.m
//  自定制collectionView动画
//
//  Created by MyMac on 15/9/18.
//  Copyright (c) 2015年 tongfang. All rights reserved.
//

#import "CustomLayout.h"
@interface CustomLayout()

@end
@implementation CustomLayout
-(void)prepareLayout
{


}
//滚动范围
-(CGSize)collectionViewContentSize
{
    NSInteger count=[self.collectionView numberOfItemsInSection:0];
     CGFloat interval=5;
    return CGSizeMake(count*(self.itemSize.width+interval)-interval,0);

}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
    NSInteger count=[self.collectionView numberOfItemsInSection:0];
    NSMutableArray*array=[NSMutableArray array];
    for (NSInteger i=0; i<count; i++) {
        NSIndexPath*indexPath=[NSIndexPath indexPathForItem:i inSection:0];
    UICollectionViewLayoutAttributes*attributes=[self layoutAttributesForItemAtIndexPath:indexPath];
        [array addObject:attributes];
    }
    
    return array;
    


}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewLayoutAttributes*attributes=[UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    attributes.size =self.itemSize;
    CGFloat interval=5;
     attributes.center = CGPointMake(self.itemSize.width/2.0+indexPath.item*(self.itemSize.width+interval), self.collectionView.frame.size.height/2.0);
     
    
   
    
    
    
    
    
    return attributes;

}
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{

    return !CGRectEqualToRect(newBounds, self.collectionView.bounds);


}
@end
